package com.enfi.api.configuration;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
/**
 * @author wind
 * @since  2020/4/3
 */
@Configuration
public class MyWebMvcConfigurer  implements WebMvcConfigurer {

    @Resource
    private SysConfig sysConfig;
    /**
     * 自定义静态资源映射处理
     * /** 将所有静态资源请求全部映射到 classpath:/res/ 目录下
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        sysConfig.getStorage().forEach((k,v)->{
            String[] a=v.toArray(new String[v.size()]);
            registry.addResourceHandler("/"+k+"/**").addResourceLocations("file:"+a);
        });
    }
}
